﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Web;

namespace Pointer.Common
{
    /// <summary>
    /// 用户身份信息存储类
    /// </summary>
    public class UserIdentity : IIdentity
    {
        public UserIdentity(int userid, string name)
        {
            if (userid > 0)
            {
                IsAuthenticated = true;
                UserId = userid;
                Name = name;
                DisplayName = name;
            }
        }

        public UserIdentity(int userid, string name, string displayname)
        {
            if (userid > 0)
            {
                IsAuthenticated = true;
                UserId = userid;
                Name = name;
                DisplayName = displayname;
            }
        }

        public string AuthenticationType
        {
            get { return "CustomAuthentication"; }
        }

        public int UserId { get; private set; }

        public bool IsAuthenticated { get; private set; }

        public string Name { get; private set; }

        public string DisplayName { get; private set; }
    }

    public class UserPrincipal : IPrincipal
    {
        public UserPrincipal(UserIdentity identity)
        {
            Identity = identity;
        }

        /// <summary>
        /// 
        /// </summary>
        public UserIdentity Identity { get; private set; }

        IIdentity IPrincipal.Identity
        {
            get { return Identity; }
        }


        bool IPrincipal.IsInRole(string role)
        {
            throw new NotImplementedException();
        }
    }
}